﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TemperatureChart;
using System.Xml;

namespace TestForm
{
    public partial class TC_TEST : Form
    {

        #region 公布属性

        private int brid;
        public int Brid
        {
            get { return brid; }
            set { brid = value; }
        }

        #endregion

        public TC_TEST()
        {
            InitializeComponent();
        }

        private void TC_TEST_Load(object sender, EventArgs e)
        {
            DataSet dsData = new DataSet();
            string sql = "exec USP_TC_QUERY " + this.brid;
            dsData = SqlHelper.ExecuteDataSet(CommandType.Text, sql);


            DataTable dtBrxx = dsData.Tables[0].Copy();
            dtBrxx.TableName = "BRXX";
            DataTable dtHljl = dsData.Tables[1].Copy();
            dtHljl.TableName = "HLJL";
            DataTable dtTwjl = dsData.Tables[2].Copy();
            dtTwjl.TableName = "TWJL";

            string xmlBrxx = dataTableToXML(dtBrxx, "");
            string xmlHljl = dataTableToXML(dtHljl, "HLJLDATA");
            string xmlTwjl = dataTableToXML(dtTwjl, "TWJLDATA");

            StringBuilder sb = new StringBuilder();
            sb.Append("<ROOT>");
            sb.Append(xmlBrxx);
            sb.Append(xmlHljl);
            sb.Append(xmlTwjl);
            sb.Append("</ROOT>");

            string xmlData = sb.ToString();

            TemperatureUC tuc = new TemperatureUC();            
            tuc.MainTitle = "传入医院";
            tuc.SecondTitle = "传入体温单";
            tuc.TimeStart = 2;
            tuc.XmlData = xmlData;
            tuc.Dock = DockStyle.Fill;
            this.Controls.Add(tuc);
        }


        private string dataTableToXML(DataTable dt,String rootNode)
        {
            StringBuilder xml=new StringBuilder();

            if (rootNode != "")
            {
                xml.Append("<"+rootNode+">");
            }
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                xml.Append("<"+dt.TableName+">");
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    xml.Append("<" + dt.Columns[j].ColumnName + ">");
                    xml.Append(dt.Rows[i][j].ToString());
                    xml.Append("</" + dt.Columns[j].ColumnName + ">");
                }
                xml.Append("</" + dt.TableName + ">");
            }
            if (rootNode != "")
            {
                xml.Append("</" + rootNode + ">");
            }           
            return xml.ToString();
        }
    }
}
